package com.example.yuejian.yuejian.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.example.yuejian.yuejian.R;
import com.example.yuejian.yuejian.activity.AskQusetionActivity;
import com.example.yuejian.yuejian.adapter.QuestionAdapter;
import com.example.yuejian.yuejian.base.BaseFragment;
import com.example.yuejian.yuejian.base.ModleListListener;
import com.example.yuejian.yuejian.bean.Question;
import com.example.yuejian.yuejian.model.MastersModel;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class QuestionFragment extends BaseFragment {

    private RecyclerView recyclerView;
    private View view;
    List<Question>list;
    private Button btn_tiwen;
    public QuestionFragment() {
        // Required empty public constructor
    }
    private ModleListListener<Question> modleListListener=new ModleListListener<Question>() {
        @Override
        public void onResponse(List<Question> l) {
            list=l;
            recyclerView.setAdapter(new QuestionAdapter(getActivity(),list));

        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(context,"fail:"+msg,Toast.LENGTH_SHORT).show();
        }
    };


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
       view=inflater.inflate(R.layout.fragment_question, container, false);
        initViews();

        initEvents();

        return view;
    }
    private void initViews()
    { recyclerView=(RecyclerView)view.findViewById(R.id.teacher_detail_question_recycleview);
        // GridLayoutManager gm = new GridLayoutManager(this.getActivity(),2);
        // 网格是的list布局   2列
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        //recyclerView.setLayoutManager(gm);
        btn_tiwen=(Button)view.findViewById(R.id.btn_question_answer);

    }

    private  void initEvents()
    {
        btn_tiwen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getActivity(),AskQusetionActivity.class);
                intent.putExtra("mid",get_Mid());
                startActivity(intent);
            }
        });
    }
    private void getdata()
    {
        MastersModel mastersModel=new MastersModel();
        mastersModel.QusetionList(get_Mid(),modleListListener);
    }
    public void onResume() {
           getdata();
        super.onResume();

    }



}
